package com.ruoyi.dept.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dept.domain.vo.BsLearnVo;
import com.ruoyi.dept.domain.bo.BsLearnBo;
import com.ruoyi.dept.service.IBsLearnService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试验室培训
 *
 * @author zyb
 * @date 2024-04-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dept/bsLearn")
public class BsLearnController extends BaseController {

    private final IBsLearnService iBsLearnService;

    /**
     * 查询试验室培训列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsLearnVo> list(BsLearnBo bo, PageQuery pageQuery) {
        return iBsLearnService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出试验室培训列表
     */
    @SaCheckLogin
    @Log(title = "试验室培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsLearnBo bo, HttpServletResponse response) {
        List<BsLearnVo> list = iBsLearnService.queryList(bo);
        ExcelUtil.exportExcel(list, "试验室培训", BsLearnVo.class, response);
    }

    /**
     * 获取试验室培训详细信息
     *
     * @param learnId 主键
     */
    @SaCheckLogin
    @GetMapping("/{learnId}")
    public R<BsLearnVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long learnId) {
        return R.ok(iBsLearnService.queryById(learnId));
    }

    /**
     * 新增试验室培训
     */
    @SaCheckLogin
    @Log(title = "试验室培训", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsLearnBo bo) {
        return toAjax(iBsLearnService.insertByBo(bo));
    }

    /**
     * 修改试验室培训
     */
    @SaCheckLogin
    @Log(title = "试验室培训", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsLearnBo bo) {
        return toAjax(iBsLearnService.updateByBo(bo));
    }

    /**
     * 删除试验室培训
     *
     * @param learnIds 主键串
     */
    @SaCheckLogin
    @Log(title = "试验室培训", businessType = BusinessType.DELETE)
    @DeleteMapping("/{learnIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] learnIds) {
        return toAjax(iBsLearnService.deleteWithValidByIds(Arrays.asList(learnIds), true));
    }
}
